package com.szzg10.mina2.chapter4;

import org.apache.mina.core.service.IoHandlerAdapter;
import org.apache.mina.core.session.IdleStatus;
import org.apache.mina.core.session.IoSession;

public class SessionHandler extends IoHandlerAdapter {

	@Override
	public void messageReceived(IoSession session, Object message)
			throws Exception {
		
		System.out.println("Message received!!!");
		
		Object object = session.getAttribute("count");
		
		Integer count = 1;
		if(object != null) {
			count = (Integer)object + 1;
		}
	
		System.out.println(count);
		
		session.setAttribute("count", count);
		
		long bytes = session.getReadBytes();
		long messages = session.getReadMessages();
		int idleCount = session.getIdleCount(IdleStatus.BOTH_IDLE);
		
		System.out.println("Bytes count: " + bytes);
		System.out.println("Messages count: " + messages);
		System.out.println("Idle count: " + idleCount);
	}
}
